package com.intel.factorytest;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import android.util.Log;
import com.intel.factorytest.util.Util;

public class TestFileOp {
    
    private String sysTestFile ="/data/data/com.intel.factorytest/sys_test.txt"; 
    private String TAG ="TestFileOp"; 
    
    public TestFileOp()
    {
    }
    public void WriteTextFile(int isSys) 
    {               
        int value = isSys;
        BufferedWriter writer=null;
        try                 
        {       
            writer = new BufferedWriter(new FileWriter(sysTestFile));
            writer.write(Integer.toString(value));
            writer.newLine();
            writer.flush();
        } catch (Exception e) 
        {  
            e.printStackTrace();      
        }finally{
            if (writer!=null) {
                Util.safeBwClose(writer);
            }
        }
    }
    public int  ReadTextFile() {
        BufferedReader reader=null;
        String s=null;
        int res = 0;
        try {
            reader = new BufferedReader(new FileReader(sysTestFile));
            while (reader!=null && (s = reader.readLine()) != null) {
                res = Integer.valueOf(s);
            }        
        } catch (IOException e) {
            Log.e(TAG,"read  result failed");
        }finally{
            if (reader!=null) {
                Util.safeBrClose(reader);
            }
        }
        return res;
    }
}
